#ifndef COPY_SHIFT
# define COPY_SHIFT(__s,__d,__sz) bcopy(__s,__d,__sz)__s=(char *)__s+__sz;__d=(char *)__s+__sz
#endif

size_t traverse_vector_copy(char *src, size_t count, size_t blocklen, size_t
                displacement, size_t sizetocopy,char
                *buffertocopy,size_t *sizecopied, int reset)

{

static int bl_idx,ele_idx,src_off,total;
int i;
size_t copiedlen=0,l_sizetocopy=sizetocopy;
char *startptr;

  if(sizetocopy<0)assert(reset); /*request for copy of entire buffer*/

  if(reset){
    bl_idx=ele_idx=src_off=0;
    total = blocklen*count;
    if(sizetocopy<0)sizetocopy=total;
  }

  if(total<sizetocopy)sizetocopy=total;
  startptr = (char *)src+src_off;
  while(copiedlen!=sizetocopy){
    if(l_sizetocopy>=blocklen){
      COPY_SHIFT(startptr,dst,blocklen);
      copiedlen+=blocklen;
      l_sizetocopy-=blocklen;
    }
    else{
      COPY_SHIFT(startptr,dst,l_sizetocopy);
      copiedlen+=l_sizetocopy;
      l_sizetocopy=0;
    }
  }

  total -=sizetocopy;
  if(sizecopied!=NULL)*sizecopied=sizetocopy;
  return(total);

}

size_t traverse_vector_ptr(void *src, size_t count, size_t blocklen, size_t
                displacement, size_t sizerequested, void **ptr_requested, size_t
                *sizeprovided, int reset)

{

static int bl_idx,ele_idx,src_off,total;

  if(reset){
    bl_idx=ele_idx=src_off=0;
  }
  if(sizerequested>blocklen){
    sizerequested = blocklen;
    *sizeprovided = *blocklen;
    *ptr_requested = (void *)((char *)src+src_off);

  }

}

size_t traverse_strided_copy(void *src, size_t levels, size_t block_len, size_t
                *displacements, size_t *counts, size_t sizetocopy, size_t *sizecopied, void
                *buffertocopy, int reset)

{

static int counts_idx[MAX_LEVELS],ele_idx,src_off;

  if(sizetocopy<0)assert(reset);

  /*request for copy of entire buffer*/
  if(reset){bl_idx=ele_idx=src_off=0;}

}


size_t traverse_strided_ptr(void *src, size_t levels, size_t block_len, size_t
                *displacements, size_t *counts, size_t sizerequested, size_t
                *sizeprovided, int reset)

{

static int counts_idx[MAX_LEVELS],ele_idx,src_off;
    
    if(reset){bl_idx=ele_idx=src_off=0;}

}
